package com.superm.service.impl;

import com.alibaba.fastjson.JSON;
import com.superm.entity.StorgageRack;
import com.superm.mappers.StorgageRackMapper;
import com.superm.service.StorgageRackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StorgageRackServiceImpl implements StorgageRackService {

    @Autowired
    private StorgageRackMapper storgageRackMp;


    /**
     * 查询所有货架
     * @return
     */
    @Override
    public List<StorgageRack> selectStorgageRack(StorgageRack storgageRack,Integer pageNo,Integer pageSize) {
            if (pageNo!=null && pageSize!=null){
                return storgageRackMp.selectAll(storgageRack, (pageNo-1)*pageSize, pageSize);
            }else{
                return storgageRackMp.selectAll(storgageRack, null,null);
            }
    }

    /**
     * 实现查询货架条数
     * @param storgageRack
     * @return
     */
    @Override
    public int selectStorgageRackCount(StorgageRack storgageRack) {

        return storgageRackMp.selectAllCount(storgageRack);
    }

    /**
     * 实现添加货架信息
     * @param storgageRack
     * @return
     */
    @Override
    public Map<String, Object> addStogageRack(StorgageRack storgageRack){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code",0);
        if(storgageRackMp.addInfoMation(storgageRack)>0){
            map.put("success",true);
            map.put("msg","添加成功!");
        }
        return map;
    }

    /**
     * 修改货架信息
     * @param storgageRack
     * @return
     */
    @Override
    public Map<String, Object> updateStogageRack(StorgageRack storgageRack){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code",0);
        if(storgageRackMp.updateInfoMation(storgageRack)>0){
            map.put("success",true);
            map.put("msg","修改成功!");
        }
        return map;
    }

    /**
     * 根据编号查询集合信息
     * @param storgageRackId
     * @return
     */
    @Override
    public StorgageRack selectIdStogageRack(Integer storgageRackId){
        return storgageRackMp.selectIdInfoMation(storgageRackId);
    }

    /**
     * 实现异步方式查询指定货架信息
     * @param storgageRackId
     * @return
     */
    @Override
    public Map<String, Object> ajaxSelectIdStogageRack(Integer storgageRackId) {
        Map<String,Object> map = new HashMap<String,Object>();
        StorgageRack storgageRack = storgageRackMp.selectIdInfoMation(storgageRackId);
        map.put("code",0);
        map.put("data", JSON.toJSONString(storgageRack));
        return map;
    }

    /**
     * 删除货架信息
     * @param storgageRackId
     * @return
     */
    @Override
    public Map<String, Object> deleteStogageRack(Integer storgageRackId) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code",0);
        if(storgageRackMp.deleteInfoMation(storgageRackId)>0){
            map.put("success",true);
            map.put("msg","删除成功!");
        }
        return map;
    }
}
